package 第五轮工作.厦门理工大学;

import com.alibaba.excel.EasyExcel;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import 第五轮工作.沈阳航空航天大学.SYHKHTTUBean;

import javax.sound.sampled.Line;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class XMLGU {
    public static void main(String[] args) throws IOException {
        String url = "https://eea.xmut.edu.cn/";
        Connection connect = Jsoup.connect(url + "szdw/dqgcx.htm");
        Document post = connect.post();
        XMLGUBean xmlguBean;
        List<XMLGUBean> xmlguBeans = new ArrayList<>();
        int i = 0;
        for (Element elementsByClass : post.getElementsByClass("f-pic-item")) {
            for (int j = 0; j < 7; j++) {
                Element element = elementsByClass.getElementsByTag("li").get(i);
                i++;
                String substring = element.getElementsByTag("a").attr("href").substring(3);
                Connection connect1 = Jsoup.connect(url + substring);
                Document post1 = connect1.post();
                for (Element byClass : post1.getElementsByClass("t-info-right")) {
                    xmlguBean = new XMLGUBean();
                    //姓名
                    String substring1 = byClass.getElementsByTag("h1").text().substring(0, 3);
                    xmlguBean.setName(substring1);
                    //职称
                    String substring2 = byClass.getElementsByTag("h1").text().substring(3);
                    xmlguBean.setZc(substring2);
                    //其余信息
                    String text = byClass.getElementsByTag("p").text();
                    xmlguBean.setQy(text);
                    xmlguBeans.add(xmlguBean);
                }

                if (i == 7) {
                    break;
                }
            }
            break;
        }
        EasyExcel.write("src/main/java/第五轮工作/厦门理工大学/XMLGU.xlsx", XMLGUBean.class).sheet("user").doWrite(xmlguBeans);

    }
}